﻿#region Copyright

// /*
// SilverlightInEnterprise
// SilverlightInEnterprise.UnitTesting.UnitTests
// SearchPersonScreenViewModelTests.cs
// 
// Author: Matt Van Horn
// Created 11/16/2011 3:38 PM
// Copyright: Silverlight in the Enterprise www.slinenterprise.com
// 
// Licensed under MS-PL http://www.opensource.org/licenses/MS-PL and while you 
// may use this in anyway you see fit and owe us nothing to do so, we wouldn't mind knowing that you got value out of the work we did (so we will do more) so 
// we ask that you leave a comment on www.slinenterprise.com or on the codeplex site slinenterprise.codeplex.com
// 
// */

#endregion

using Microsoft.VisualStudio.TestTools.UnitTesting;
using SilverlightInEnterprise.UnitTesting.TargetApplication.ViewModels;

namespace SilverlightInEnterprise.UnitTesting.UnitTests.Screens
{
    [TestClass]
    public class SearchPersonScreenViewModelTests
    {
        private SearchPersonScreenViewModel CreateSearchPersonScreenViewModel()
        {
            return new SearchPersonScreenViewModel();
        }

        [TestMethod]
        public void CreateSearchPersonScreenViewModelTest()
        {
            var vm = this.CreateSearchPersonScreenViewModel();
            Assert.IsNotNull(vm, "the vm is null");
            Assert.IsNull(vm.SSN, "this screen should not have SSN set");
            Assert.IsNull(vm.FirstName, "this screen should not have first name set");
            Assert.IsNull(vm.LastName, "this screen should not have last name set");
            Assert.IsNotNull(vm.Title, "title is null");
            Assert.AreEqual(vm.Title, "Search Person",
                            "the title should be Search Person is is however set to: " + vm.Title);
            Assert.IsNotNull(vm.SearchCommand, "Search command should not be null");
            Assert.IsTrue(vm.Location == ScreenLocation.Left);
        }

        [TestMethod]
        public void EnsureNoSSNAndLastNameLessThanThreeCharactersCantSearch()
        {
            var vm = this.CreateSearchPersonScreenViewModel();
            vm.FirstName = "asdf";
            vm.LastName = "ds";
            vm.SSN = null;
            Assert.IsFalse(vm.SearchCommand.CanExecute(null),
                           "ssn = null last name is 2 characters we shouldn't be able to search");
            vm.LastName = "1234";
            Assert.IsTrue(vm.SearchCommand.CanExecute(null));
        }

        [TestMethod]
        public void EnsureEnsureSsnIsNineDigitsAndLastNameIsLessThanThreeCharactersOrCantSearch()
        {
            var vm = this.CreateSearchPersonScreenViewModel();
            vm.LastName = "1";
            vm.SSN = "111-111-1111".Replace("-", "");
            Assert.IsFalse(vm.SearchCommand.CanExecute(null), "ssn is not 9 digits so cant search");

            vm.SSN = "111-11-1111".Replace("-", "");
            Assert.IsTrue(vm.SearchCommand.CanExecute(null), "SSN is 9 digits so we should be able to search but can't");
        }

        [TestMethod]
        public void EnsureChangeCanExecuteFiresOnSearchCommandWhenChanginFirstLastOrSsn()
        {
            var vm = this.CreateSearchPersonScreenViewModel();
            int fireCount = 0;


            vm.SearchCommand.CanExecuteChanged += (s, e) => { fireCount++; };
            vm.SSN = "111-11-1111";
            vm.FirstName = "Matt";
            vm.LastName = "Van Horn";
            Assert.AreEqual(3, fireCount, "Changed 3 properties expected can execute to have fired 3 times");
        }
    }
}